package org.feiye.studyday02;

import java.util.Scanner;

public class CardNumSum {
	public static void main(String[] args) {
		// 键盘输入四位数字的会员卡号
		// 使用“/”和“%”运算符分解获得会员卡各个位上的数字
		// 将各个位上数字求和
		// 判断是否中奖
		Scanner input = new Scanner(System.in);
		System.out.println("请输入4位会员卡号：");
		int cardNum = input.nextInt();
		System.out.println("会员卡号是：" + cardNum);
		int qianWei = cardNum / 1000;
		int baiWei = cardNum / 100 % 10;
		int shiWei = cardNum / 10 % 10;
		int geWei = cardNum % 10;
		int sum = qianWei + baiWei + shiWei + geWei;
		System.out.println("千位数：" + qianWei + "," + "百位数：" + baiWei + "," + "十位数：" + shiWei + "," + "个位数：" + geWei);
		System.out.println("会员卡号" + cardNum + "各位之和：" + sum);
		String result = (sum > 20) ? "您中奖了，奖品是MP3！" : "感谢参与!";
		System.out.println("会员卡号" + cardNum + "的会员，" + result);
	}
}
